package com.deram.ctin.serv.main.service.impl;

import com.deram.ctin.serv.business.api.*;
import com.deram.ctin.serv.business.entity.BusinessEnterAssets;
import com.deram.ctin.serv.business.filter.*;
import com.deram.ctin.serv.enter.api.EnterChangeLogApi;
import com.deram.ctin.serv.enter.api.EnterInfoApi;
import com.deram.ctin.serv.enter.api.EnterMainUserApi;
import com.deram.ctin.serv.enter.api.EnterRecruitApi;
import com.deram.ctin.serv.enter.filter.EnterChangeLogFilter;
import com.deram.ctin.serv.enter.filter.EnterInfoFilter;
import com.deram.ctin.serv.enter.filter.EnterMainUserFilter;
import com.deram.ctin.serv.enter.filter.EnterRecruitFilter;
import com.deram.ctin.serv.main.service.EnterDetailService;
import com.deram.ctin.serv.main.vo.EnterDetailVo;
import com.deram.ctin.serv.main.vo.EnterDetailYearVo;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/29
 */
@Service
public class EnterDetailServiceImpl implements EnterDetailService {

    @Autowired
    private EnterInfoApi enterInfoApi;
    @Autowired
    private BusinessInfoApi businessInfoApi;
    @Autowired
    private BusinessShareholderApi businessShareholderApi;
    @Autowired
    private EnterMainUserApi enterMainUserApi;
    @Autowired
    private EnterChangeLogApi enterChangeLogApi;
    @Autowired
    private BusinessInvestmentApi businessInvestmentApi;
    @Autowired
    private BusinessJudgementApi businessJudgementApi;
    @Autowired
    private BusinessCourtApi businessCourtApi;
    @Autowired
    private BusinessCourtSessionApi businessCourtSessionApi;
    @Autowired
    private BusinessEnforcementApi businessEnforcementApi;
    @Autowired
    private BusinessDishonestApi businessDishonestApi;
    @Autowired
    private BusinessJudicialSaleApi businessJudicialSaleApi;
    @Autowired
    private BusinessAbnormalApi businessAbnormalApi;
    @Autowired
    private BusinessArrearsApi businessArrearsApi;
    @Autowired
    private BusinessPledgedApi businessPledgedApi;
    @Autowired
    private BusinessMortgageApi businessMortgageApi;
    @Autowired
    private BusinessBrandApi businessBrandApi;
    @Autowired
    private BusinessPatentApi businessPatentApi;
    @Autowired
    private BusinessCopyrightApi businessCopyrightApi;
    @Autowired
    private BusinessSoftwareApi businessSoftwareApi;
    @Autowired
    private BusinessDomainApi businessDomainApi;
    @Autowired
    private BusinessQualificationApi businessQualificationApi;
    @Autowired
    private EnterRecruitApi enterRecruitApi;
    @Autowired
    private BusinessTenderApi businessTenderApi;
    @Autowired
    private BusinessEnterAssetsApi businessEnterAssetsApi;
    @Autowired
    private BusinessTransferApi businessTransferApi;

    @Override
    public EnterDetailVo findDetail(Long id) {
        EnterDetailVo result = new EnterDetailVo();
        result.setEnterInfo(enterInfoApi.findById(id));
        result.setBusinessInfo(businessInfoApi.find(id));

        BusinessShareholderFilter businessShareholderFilter = new BusinessShareholderFilter();
        businessShareholderFilter.setEnterId(id);
        EnterMainUserFilter enterMainUserFilter = new EnterMainUserFilter();
        enterMainUserFilter.setEnterId(id);
        EnterChangeLogFilter enterChangeLogFilter = new EnterChangeLogFilter();
        enterChangeLogFilter.setEnterId(id);
        EnterInfoFilter enterInfoFilter = new EnterInfoFilter();
        enterInfoFilter.setFatherId(id);
        BusinessInvestmentFilter businessInvestmentFilter = new BusinessInvestmentFilter();
        businessInvestmentFilter.setEnterId(id);
        BusinessJudgementFilter businessJudgementFilter = new BusinessJudgementFilter();
        businessJudgementFilter.setEnterId(id);
        BusinessCourtFilter businessCourtFilter = new BusinessCourtFilter();
        businessCourtFilter.setEnterId(id);
        BusinessCourtSessionFilter businessCourtSessionFilter = new BusinessCourtSessionFilter();
        businessCourtSessionFilter.setEnterId(id);
        BusinessEnforcementFilter businessEnforcementFilter = new BusinessEnforcementFilter();
        businessEnforcementFilter.setEnterId(id);
        BusinessDishonestFilter businessDishonestFilter = new BusinessDishonestFilter();
        businessDishonestFilter.setEnterId(id);
        BusinessJudicialSaleFilter businessJudicialSaleFilter = new BusinessJudicialSaleFilter();
        businessJudicialSaleFilter.setEnterId(id);
        BusinessAbnormalFilter businessAbnormalFilter = new BusinessAbnormalFilter();
        businessAbnormalFilter.setEnterId(id);
        BusinessArrearsFilter businessArrearsFilter = new BusinessArrearsFilter();
        businessArrearsFilter.setEnterId(id);
        BusinessPledgedFilter businessPledgedFilter = new BusinessPledgedFilter();
        businessPledgedFilter.setEnterId(id);
        BusinessMortgageFilter businessMortgageFilter = new BusinessMortgageFilter();
        businessMortgageFilter.setEnterId(id);
        BusinessBrandFilter businessBrandFilter = new BusinessBrandFilter();
        businessBrandFilter.setEnterId(id);
        BusinessPatentFilter businessPatentFilter = new BusinessPatentFilter();
        businessPatentFilter.setEnterId(id);
        BusinessCopyrightFilter businessCopyrightFilter = new BusinessCopyrightFilter();
        businessCopyrightFilter.setEnterId(id);
        BusinessSoftwareFilter businessSoftwareFilter = new BusinessSoftwareFilter();
        businessSoftwareFilter.setEnterId(id);
        BusinessDomainFilter businessDomainFilter = new BusinessDomainFilter();
        businessDomainFilter.setEnterId(id);
        BusinessQualificationFilter businessQualificationFilter = new BusinessQualificationFilter();
        businessQualificationFilter.setEnterId(id);
        EnterRecruitFilter enterRecruitFilter = new EnterRecruitFilter();
        enterRecruitFilter.setEnterId(id);
        BusinessTenderFilter businessTenderFilter = new BusinessTenderFilter();
        businessTenderFilter.setEnterId(id);

        result.setBusinessShareholderList(businessShareholderApi.list(businessShareholderFilter));
        result.setEnterMainUserList(enterMainUserApi.list(enterMainUserFilter));
        result.setEnterChangeLogList(enterChangeLogApi.list(enterChangeLogFilter));
        result.setChildEnterInfoList(enterInfoApi.list(enterInfoFilter));
        result.setBusinessInvestmentList(businessInvestmentApi.list(businessInvestmentFilter));
        result.setBusinessJudgementList(businessJudgementApi.list(businessJudgementFilter));
        result.setBusinessCourtList(businessCourtApi.list(businessCourtFilter));
        result.setBusinessCourtSessionList(businessCourtSessionApi.list(businessCourtSessionFilter));
        result.setBusinessEnforcementList(businessEnforcementApi.list(businessEnforcementFilter));
        result.setBusinessDishonestList(businessDishonestApi.list(businessDishonestFilter));
        result.setBusinessJudicialSaleList(businessJudicialSaleApi.list(businessJudicialSaleFilter));
        result.setBusinessAbnormalList(businessAbnormalApi.list(businessAbnormalFilter));
        result.setBusinessArrearsList(businessArrearsApi.list(businessArrearsFilter));
        result.setBusinessPledgedList(businessPledgedApi.list(businessPledgedFilter));
        result.setBusinessMortgageList(businessMortgageApi.list(businessMortgageFilter));
        result.setBusinessBrandList(businessBrandApi.list(businessBrandFilter));
        result.setBusinessPatentList(businessPatentApi.list(businessPatentFilter));
        result.setBusinessCopyrightList(businessCopyrightApi.list(businessCopyrightFilter));
        result.setBusinessSoftwareList(businessSoftwareApi.list(businessSoftwareFilter));
        result.setBusinessDomainList(businessDomainApi.list(businessDomainFilter));
        result.setBusinessQualificationList(businessQualificationApi.list(businessQualificationFilter));
        result.setEnterRecruitList(enterRecruitApi.list(enterRecruitFilter));

        result.setBusinessTenderList(businessTenderApi.list(businessTenderFilter));

        //年份信息
        List<Integer> annualYearList = businessInfoApi.listYear(id);
        result.setAnnualYearList(annualYearList);

        List<EnterDetailYearVo> enterDetailYearVoList = Lists.newArrayList();
        BusinessDomainFilter domainFilter = new BusinessDomainFilter();
        domainFilter.setEnterId(id);
        domainFilter.setHasYear(true);
        BusinessShareholderFilter shareholderFilter = new BusinessShareholderFilter();
        shareholderFilter.setEnterId(id);
        shareholderFilter.setHasYear(true);
        BusinessInvestmentFilter investmentFilter = new BusinessInvestmentFilter();
        investmentFilter.setEnterId(id);
        investmentFilter.setHasYear(true);
        BusinessTransferFilter transferFilter = new BusinessTransferFilter();
        transferFilter.setEnterId(id);
        transferFilter.setHasYear(true);
        for (Integer year : annualYearList) {
            EnterDetailYearVo enterDetailYearVo = new EnterDetailYearVo();
            enterDetailYearVo.setYear(year);
            enterDetailYearVo.setBusinessInfo(businessInfoApi.findByYear(id, year));
            enterDetailYearVo.setBusinessEnterAssets(businessEnterAssetsApi.findByYear(id, year));

            domainFilter.setYear(year);
            shareholderFilter.setYear(year);
            investmentFilter.setYear(year);
            transferFilter.setYear(year);

            enterDetailYearVo.setBusinessDomainList(businessDomainApi.list(domainFilter));
            enterDetailYearVo.setBusinessShareholderList(businessShareholderApi.list(shareholderFilter));
            enterDetailYearVo.setBusinessInvestmentList(businessInvestmentApi.list(investmentFilter));
            enterDetailYearVo.setBusinessTransferList(businessTransferApi.list(transferFilter));

            enterDetailYearVoList.add(enterDetailYearVo);
        }

        result.setEnterDetailYearVoList(enterDetailYearVoList);
        return result;
    }
}
